<template>
	<view class="">
		<view class="tops bgw">
			<u-tabs :list="list" active-color="#1BBF80" :is-scroll="false" font-size="32" :current="current" @change="change"></u-tabs>
			<view class="h20"></view>
			<search />
			<view class="h20"></view>
		</view>
		<view class="contents">
			<special ref="specials" v-show="current == 0"></special>
			<recommend v-show="current == 1" ref="recommends"></recommend>
			<dynamicIndex ref="dynamics" :url="url" v-show="current == 2"></dynamicIndex>
		</view>
		<noLocation @success="noLocationSuccess" ref="noLocation"></noLocation>
		<newlyBuild ref="newlyBuild"></newlyBuild>
	</view>
</template>

<script>
	import {
		DynamicList,
		DynamicListUrl
	} from '@/api/api.js'
	import special from './special/special.vue'
	import recommend from './recommend/recommend.vue'
	import search from '../../components/search/search.vue'
	import noLocation from '../../components/noLocation/noLocation.vue'
	import dynamicIndex from '../../components/dynamic/dynamic-Index.vue'
	import {
		mapState,
		mapActions
	} from "vuex";
	export default {
		components: {
			special,
			recommend,
			search,
			dynamicIndex,
			noLocation
		},
		computed: {
			...mapState(['longitude', 'latitude'])
		},
		onNavigationBarButtonTap(e) {
			this.$navigateTo('../more/more')
		},
		data() {
			return {
				url: DynamicListUrl,
				DynamicData: [],
				triggered: false,
				list: [{
					name: '关注'
				}, {
					name: '推荐'
				}, {
					name: '动态'
				}],
				current: 1,
				pageNumber: 1,
				pageSize: 10,
				stops: 0,
				data: []
			};
		},
		onPullDownRefresh() {
			if (this.current == 0) {
				this.$refs['specials'].inits(); 
			}
			if (this.current == 1) {
				this.$refs['recommends'].inits();
			}
			if (this.current == 2) {
				this.$refs['dynamics'].inits();
			}
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			if (this.current == 0) {
				this.$refs['specials'].checking();
			}
			if (this.current == 1) {
				this.$refs['recommends'].checking();
			}
			if (this.current == 2) {
				this.$refs['dynamics'].checking();
			}
		},
		onLoad() { 
			uni.getLocation({
				type: 'wgs84',
				success: (res) => {
					this.$store.commit("setlongitude", res.longitude);
					this.$store.commit("setlatitude", res.latitude);
					// this.$refs['specials'].inits();
					this.$refs['recommends'].inits();
					// this.$refs['dynamics'].inits();
				},
				fail: (err) => {
					this.$refs['noLocation'].show()
				}
			});
			uni.onTabBarMidButtonTap(() => {
				this.$refs['newlyBuild'].show()
				// this.$navigateTo('../new/new')
			})
			let token = uni.getStorageSync('token')
			let loginData = {
				token:token
			}
			this.$store.commit("login", loginData); 

			
		},
		mounted() { 
			// #ifdef APP-PLUS
				uni.sendNativeEvent('infoUser', {
					msg: 'unimp message!!!'
				}, ret => {
					ret = JSON.parse(ret)
					this.$store.commit("login", {
						name: ret.name,
						img: ret.avator
					});
				})
			// #endif 
			// this.$refs['dynamics'].inits();
		},
		methods: {
			noLocationSuccess() {
				this.$refs['specials'].inits();
				this.$refs['recommends'].inits();
				this.$refs['dynamics'].inits();
			},
			change(index) {
				this.current = index;
				if (this.current == 0) {
					this.$refs['specials'].inits();
				}
				if (this.current == 1) {
					this.$refs['recommends'].inits();
				}
				if (this.current == 2) {
					this.$refs['dynamics'].inits();
				}
			}
		}
	};
</script>
<style lang="less" scoped>
	.tops {
		position: fixed;
		left: 0;
		width: 100%;
		z-index: 999;
	}

	.h20 {
		height: 6rpx;
	}

	.contents {
		padding-top: 180rpx;
		padding-bottom: 180rpx;
	}

	.conten_main {}
</style>
